package com.agentframework.core.annotation;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.annotation.AnnotationAttributes;

/**
 * 执行具体的扫描和处理逻辑
 * 负责扫描带有@Agent注解的类
 * 并处理它们之间的依赖关系
 */
public class AgentClassPathScanner extends AbstractClassPathScanner {

    public AgentClassPathScanner(BeanDefinitionRegistry registry) {
        super(registry, Agent.class);
    }

    @Override
    protected void addPropertyValue(BeanDefinition definition) {
        if (definition instanceof AnnotatedBeanDefinition annotatedDef) {
            AnnotationAttributes attrs = AnnotationAttributes.fromMap(annotatedDef.getMetadata().getAnnotationAttributes(Agent.class.getName()));
            if (attrs != null) {
                // 检查类是否有对应的属性，有才设置
                if (attrs.containsKey("scope")) {
                    definition.setScope(attrs.getEnum("scope").name().toLowerCase());
                }
                if (attrs.containsKey("lazyInitialization")) {
                    definition.setLazyInit(attrs.getBoolean("lazyInitialization"));
                }
            }
        }
    }

}